﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DigitalSolutionControls
{
    public class Processing : PictureBox
    {
        public Processing()
        {
            this.MinimumSize = new System.Drawing.Size(35, 35);
            this.Size = new System.Drawing.Size(35, 35);
            this.Image = Properties.Resources.processing;
            this.SizeMode = PictureBoxSizeMode.CenterImage;
            this.Visible = false;
        }

        private void FindChild(Control ctr, bool enable)
        {
            if (ctr.HasChildren && ctr.GetType() != typeof(Paging) && ctr.GetType() != typeof(ListPanel)
                && ctr.GetType() != typeof(FormHeader))
            {
                foreach (Control c in ctr.Controls)
                {
                    FindChild(c, enable);
                }
            }
            else
            {
                if (ctr.GetType() != typeof(Processing))
                    ctr.Enabled = enable;
            }
        }

        public void ShowProcessing()
        {
            this.Show();
            FindChild(this.FindForm(), false);
        }

        public void HideProcessing()
        {
            FindChild(this.FindForm(), true);
            this.Hide();
        }
    }
}
